package com.bdqn.design.proxy.cglib;

import net.sf.cglib.proxy.Enhancer;

/**
 * IntermediaryCGLIBProxyFactory 代理工厂
 *
 * @author LILIBO
 * @since 2023-10-10
 */
public class IntermediaryCGLIBProxyFactory {

    private static final IntermediaryMethodInterceptor callback = new IntermediaryMethodInterceptor();

    /**
     * 工厂方法
     *
     * @param target 需要被代理的目标对象
     * @param <T>
     * @return 返回生成好的代理对象
     */
    public static <T> T create(Class<T> target) {
        Enhancer enhancer = new Enhancer();
        enhancer.setCallback(callback);
        enhancer.setSuperclass(target);
        return (T) enhancer.create();
    }

}
